﻿using EnhancedUI.EnhancedScroller;
using System.Collections.Generic;
using UnityEngine;

public class ScrollerManager : MonoBehaviour, IEnhancedScrollerDelegate
{
    public static ScrollerManager instance;
    public EnhancedScroller m_Scroller;
    public SelectButton m_Cell;
    public RectTransform m_RectTransform;

    private List<string> _data;

    void Start()
    {
        instance = this;
        InitScroller();
        
    }

    public void InitScroller()
    {
        m_Scroller.Delegate = this;
        InitData();
    }

    public void ReloadData()
    {
        m_Scroller.ReloadData();
    }

    private void InitData()
    {
        _data = new List<string>();
        foreach (string key in Utils.project_dict.Keys)
        {
            _data.Add(key);
        }
        m_Scroller.ReloadData();
    }

    public int GetNumberOfCells(EnhancedScroller scroller)
    {
        return _data.Count;
    }

    public float GetCellViewSize(EnhancedScroller scroller, int dataIndex)
    {
        return 52;
    }

    public EnhancedScrollerCellView GetCellView(EnhancedScroller scroller, int dataIndex, int cellIndex)
    {
        SelectButton cellView = scroller.GetCellView(m_Cell) as SelectButton;
        cellView.SetData(_data[dataIndex]);
        return cellView;
    }

}
